#!/bin/sh

:<<EOF

${!myMap[*]}     keySet   ;  Here   has    Exclamation mark ;

${myMap[*]}      valueSet ;  Here      has no  Exclamation mark ;


EOF



#在使用map时，需要先声明，否则结果可能与预期不同, 不声明底下报错，array可以不声明;
declare -A site
site["google"]="www.google.com"
site["runoob"]="www.runoob.com"
site["taobao"]="www.taobao.com"




echo " key runnoob  value ${site['runoob']}";

echo "map keys  are : ${!site[*]}" ;
echo "map keys  are : ${!site[@]}" ;



echo "数组的元素为: ${site[*]}"
echo "数组的元素为: ${site[@]}"

echo "数组的元素为: ${site[*]}"
echo "数组的元素为: ${site[@]}"


echo "map size is  ${#site[*]}"
echo "map size is  ${#site[@]}"




echo "一、定义Map:declare -A myMap=([\"myMap00\"]=\"00\" [\"myMap01\"]=\"01\")"
declare -A myMap=(["my00"]="00" ["my01"]="01")
myMap["name"]="sky"
myMap["password"]="1234"

echo "二、输出所有的key:"
echo ${!myMap[@]}

echo "三、输出所有value:"
echo ${myMap[@]}

echo "四、输出map的长度:"
echo ${#myMap[@]}

echo "五、   Traversing, 根据key找到对应的value:"
for key in ${!myMap[*]};do
  echo "key:"$key
  echo "value:"${myMap[$key]}
done

echo "Traversing 所有的key:"
for key in ${!myMap[@]};do
  echo "key:"$key
  echo "value:"${myMap[$key]}
done

echo "七、 Traversing 所有value:"
for val in ${myMap[@]};do
  echo "value:"$val
done

echo "八, 根据key 获取 value"

echo  "value:"${myMap[name]}
echo  "value:"${myMap[password]}

